home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 27 / CU Amiga Magazine's Super CD-ROM 27 (1998)(EMAP Images)(GB)[!][issue 1998-10].iso / CUCD / Programming / BlitzList / BlitzListFiles / SavePaletteStd.asc < prev    next >
Encoding:
Text File  |  1998-08-01  |  1.8 KB  |  67 lines

  1. ; Save a standard palette (PPaint palette)
  2. ; By   : Cyanure (Mathias.P@wanadoo.fr)
  3. ; Date : 26/07/98
  4.  
  5. Statement SavePaletteFile{NumberBmap.b,FileName.s}
  6.   DEFTYPE .b NumberPlanes
  7.   DEFTYPE .w NumberColors,FSize
  8.  
  9.   NumberPlanes=Peek.b(Addr BitMap(NumberBmap)+5)
  10.   NumberColors=2^NumberPlanes
  11.   FSize=3*NumberColors+48               ; File size
  12.  
  13.   If OpenFile(1,FileName.s)=-1
  14.     *pf=AllocMem_(FSize,0)          ; Memory for the palette file
  15.     *pf0=*pf                        ; Beginning of the palette file
  16.                                       address
  17.     Poke.l *pf,$464f524d            ; FORM
  18.     Poke.l *pf+4,FSize-8            ;
  19.     Poke.l *pf+8,$494c424d          ; ILBM
  20.     Poke.l *pf+12,$424d4844         ; BMHD
  21.     Poke.l *pf+16,20                ; Size of the BMHD chunk
  22.     Poke.l *pf+20,0                 ; width and height
  23.     Poke.l *pf+24,0                 ; x and y
  24.     Poke.l *pf+28,$03020180         ; I don't know why but it works !
  25.     Poke.l *pf+32,0                 ; transparency and aspect
  26.     Poke.l *pf+36,0                 ; page width and page height
  27.     Poke.l *pf+40,$434d4150         ; CMAP
  28.     Poke.l *pf+44,NumberColors*3    ; Size of the CMAP chunk
  29.  
  30.     *pf+48                          ; Increases the pointer
  31.  
  32.     For c=0 To NumberColors-1
  33.       Poke.b *pf,AGARed(c)
  34.       Poke.b *pf+1,AGAGreen(c)
  35.       Poke.b *pf+2,AGABlue(c)
  36.       *pf+3
  37.     Next c
  38.  
  39.     WriteMem 1,*pf0,FSize            ; Writes in file #1
  40.     FreeMem_ *pf0,FSize
  41.     CloseFile 1
  42.  
  43.   EndIf
  44.  
  45. End Statement
  46.  
  47. .main
  48.  
  49. WBStartup
  50. NoCli
  51.  
  52. ; I suppose the palette you want to save is one of an open bitmap
  53. ; So, I open such a bitmap :
  54. Screen 0,0,0,320,256,8,0,"title",1,2
  55. ScreensBitMap 0,0
  56. LoadBitMap 0,"images:iff/ofs.iff",0   ; chooses a bitmap
  57. LoadPalette 0,"images:iff/ofs.iff"
  58. Use Palette 0
  59.  
  60. SavePaletteFile{0,"ram:PaletteStd.col"}
  61.  
  62. End
  63.  
  64.  
  65.  
  66.  
  67.